import java.util.List;

import javax.swing.table.DefaultTableModel;

import modelo.Jugador;


public class Ventana extends javax.swing.JFrame {

	private Cliente c;
	
    /** Creates new form Ventana */
    public Ventana() {
    	c = new Cliente();
        initComponents();
        this.setVisible(true);
    }

	public static void main(String[] args){
		new Ventana();
	}

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        buttonGroup1 = new javax.swing.ButtonGroup();
        buttonGroup2 = new javax.swing.ButtonGroup();
        txtClub = new javax.swing.JTextField();
        optZona1 = new javax.swing.JRadioButton();
        optZona2 = new javax.swing.JRadioButton();
        optCategoria84 = new javax.swing.JRadioButton();
        optCategoria85 = new javax.swing.JRadioButton();
        jLabel1 = new javax.swing.JLabel();
        jScrollPane1 = new javax.swing.JScrollPane();
        jTable1 = new javax.swing.JTable();
        jButton1 = new javax.swing.JButton();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

        buttonGroup1.add(optZona1);
        optZona1.setText("Zona 1");

        buttonGroup1.add(optZona2);
        optZona2.setText("Zona 2");

        buttonGroup2.add(optCategoria84);
        optCategoria84.setText("Categoría 84");

        buttonGroup2.add(optCategoria85);
        optCategoria85.setText("Cateogría 85");

        jLabel1.setText("Club:");

        jTable1.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null}
            },
            new String [] {
                "Nombre", "TipoDoc", "NroDoc", "FecNac"
            }
        ) {
            Class[] types = new Class [] {
                java.lang.String.class, java.lang.String.class, java.lang.String.class, java.lang.String.class
            };
            boolean[] canEdit = new boolean [] {
                false, false, false, false
            };

            public Class getColumnClass(int columnIndex) {
                return types [columnIndex];
            }

            public boolean isCellEditable(int rowIndex, int columnIndex) {
                return canEdit [columnIndex];
            }
        });
        jScrollPane1.setViewportView(jTable1);

        jButton1.setText("Obtener");
        jButton1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton1ActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addGap(49, 49, 49)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(layout.createSequentialGroup()
                                .addComponent(jLabel1)
                                .addGap(18, 18, 18)
                                .addComponent(txtClub, javax.swing.GroupLayout.PREFERRED_SIZE, 212, javax.swing.GroupLayout.PREFERRED_SIZE))
                            .addGroup(layout.createSequentialGroup()
                                .addComponent(optCategoria84)
                                .addGap(18, 18, 18)
                                .addComponent(optCategoria85))
                            .addGroup(layout.createSequentialGroup()
                                .addComponent(optZona1)
                                .addGap(18, 18, 18)
                                .addComponent(optZona2))))
                    .addGroup(layout.createSequentialGroup()
                        .addGap(20, 20, 20)
                        .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 359, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(layout.createSequentialGroup()
                        .addGap(148, 148, 148)
                        .addComponent(jButton1)))
                .addContainerGap(21, Short.MAX_VALUE))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(optZona1)
                    .addComponent(optZona2))
                .addGap(18, 18, 18)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(optCategoria84)
                    .addComponent(optCategoria85))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(txtClub, javax.swing.GroupLayout.PREFERRED_SIZE, 36, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel1))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 30, Short.MAX_VALUE)
                .addComponent(jButton1)
                .addGap(18, 18, 18)
                .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 162, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap())
        );

        pack();
    }

    private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed
    	int zona, categoria;
    	
    	if (optZona1.isSelected()){
    		zona = 1;
    	} else{
    		zona = 2;
    	}
    	
    	if (optCategoria84.isSelected()){
    		categoria = 84;
    	} else{
    		categoria = 85;
    	}
    	
    	List<Jugador> jugadores = c.getJugadores(zona, categoria, txtClub.getText());
    	
    	String[][] tabla = new String[jugadores.size()][4];
    	
    	for (int i = 0; i < jugadores.size(); i++){
    		tabla[i][0] = jugadores.get(i).getNombre();
    		tabla[i][1] = jugadores.get(i).getTipoDoc();
    		tabla[i][2] = "" + jugadores.get(i).getNroDoc();
    		tabla[i][3] = jugadores.get(i).getFechaNac().toString();
    	}
    	
    	jTable1.setModel(new DefaultTableModel(tabla, new String [] {
                "Nombre", "TipoDoc", "NroDoc", "FecNac"
            }));
    }


    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.ButtonGroup buttonGroup1;
    private javax.swing.ButtonGroup buttonGroup2;
    private javax.swing.JButton jButton1;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JTable jTable1;
    private javax.swing.JRadioButton optCategoria84;
    private javax.swing.JRadioButton optCategoria85;
    private javax.swing.JRadioButton optZona1;
    private javax.swing.JRadioButton optZona2;
    private javax.swing.JTextField txtClub;
    // End of variables declaration//GEN-END:variables

}
